<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Test01</title>
</head>
<body>
<script type="text/javascript">
    let arr01 = [10, 20, 30];
    let obj01 = {"aa": 10, "bb": 20, "cc": 30};

    let set01 = new Set(arr01);
    let map01 = new Map([["aa", 10], ["bb", 20], ["cc", 30]]);

    console.dir(arr01);
    console.dir(obj01);

    console.dir(set01);
    console.dir(map01);

    // let it01 = arr01[Symbol.iterator]();
    // console.log(it01.next().value);
    // console.log(it01.next().value);
    // console.log(it01.next().value);
    // console.log(it01.next().value);

    // let it02 = set01[Symbol.iterator]();
    // console.log(it02.next().value);
    // console.log(it02.next().value);
    // console.log(it02.next().value);
    // console.log(it02.next().value);

    // let it03 = map01.entries()[Symbol.iterator]();
    // console.log(it03.next().value);
    // console.log(it03.next().value);
    // console.log(it03.next().value);
    // console.log(it03.next().value);

    // let it04 = obj01[Symbol.iterator]();

    let obj02 = {
        data: [10, 20, 30],
        [Symbol.iterator]() {
            let i = 0;
            let that = this;
            return {
                next() {
                    if (i < that.data.length) {
                        return {done: false, value: that.data[i++]};
                    } else {
                        return {done: true};
                    }
                },
                return() {
                    console.log("call return");
                    return {done: true};
                },
                throw() {
                }
            }
        }
    };

    let it05 = obj02[Symbol.iterator]();

    // console.log(it05.next().value);
    // console.log(it05.next().value);
    // console.log(it05.next().value);
    // console.log(it05.next());

    console.dir(it05);

    for (let item of obj02) {
        if (item < 20) {
            console.log(item);
        } else {
            break;
        }
    }
</script>
</body>
</html>